//
//  HomePlanViewModel.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/22.
//

import Foundation
import Moya


enum HomePlanApi {
    case recommandPlan(current:Int?,planType:Int?)
    case todayPlan(today:String?)
    case mobileApi(mobile:String?,verif:String?)
    case mobileSend(mobile:String)
}

extension HomePlanApi:TargetType {
    
    var baseURL: URL {
        return URL.init(string: Moya_baseURL)!
    }
    
    var path: String {
        switch self {
        case .recommandPlan:
            return "api/admin/planForApp/getActionPlanPage"
        case .todayPlan:
            return  "api/admin/planForApp/getUserPlanList"
        case .mobileApi:
            return "api/app/register/login"
        case .mobileSend:
            return "api/app/register/sendCode"
        }
    }
    var method:Moya.Method {
        switch self {
        case .recommandPlan,.todayPlan:
            return .get
        case .mobileSend:
            return .post
        case .mobileApi:
            return .post
       
        }
    }
    
    var sampleData: Data {
        return Data()
    }
    
    
    var task: Task {
        switch self {
        case let .recommandPlan(current, planType):
            return .requestParameters(parameters: ["current":current ?? 1,"planType":planType ?? "","size":20], encoding: URLEncoding.default)
        case let .todayPlan(today):
            return .requestParameters(parameters: ["planDate":today ?? ""], encoding: URLEncoding.default)
        case let .mobileSend(mobile):
            return .requestParameters(parameters: ["phone":mobile], encoding: JSONEncoding.default)
        case let .mobileApi(mobile, verif):
            return .requestParameters(parameters: ["phone":mobile ?? "","code":verif ?? ""], encoding: JSONEncoding.default)
       
        }
    }
    
    var headers: [String : String]? {
        let tokenName:String = UserDefaults.standard.string(forKey: "LoginName") ?? ""
        let tokenValue:String = UserDefaults.standard.string(forKey: "LoginToken") ?? ""
        return [tokenName:tokenValue]
    }
    
    
}
